package com.hs.jhzd.controller;

import com.hs.jhzd.entity.JqYxjqxxbEntity;
import com.hs.jhzd.repository.JqYxJqxxbRepository;
import com.hs.jhzd.utils.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/acp-cloud/alarm")
@Slf4j
public class JqYxJqxxbController {

    @Autowired
    private JqYxJqxxbRepository repository;


    @RequestMapping("/jqyxjqxxb/list")
    @ResponseBody
    public List<JqYxjqxxbEntity> find(String rybh, @RequestParam(value = "time", required = false) String time) {
        List<JqYxjqxxbEntity> all = null;
        if (null == time) {
            all = repository.findByRybh(rybh);
        } else {
            String[] split = time.split("-");
            String newStr = split[1].replaceAll("^(0+)", "");
            all = repository.findByRybhcAndCjsj(rybh, DateUtils.getFisrtDayOfMonth(Integer.parseInt(split[0]), Integer.parseInt(newStr)), DateUtils.getLastDayOfMonth(Integer.parseInt(split[0]), Integer.parseInt(newStr)));
        }
        return all;
    }


}
